package net.sf.xoperator.ui.txt;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;

import net.sf.xoperator.blackboard.NoPlanBlackBoardControl;
import net.sf.xoperator.ui.StringMessage;
/**
 * template for an interaction. 
 * @author joerg
 *
 */
public abstract class Interaction {
   /**
    * 
    * @return the keyword(s) that will trigger the execution of this command. 
    */
   public abstract String getKeyWord();
   
   
   /**
    * 
    * @return a pattern to check if the call string is appropriate for the client
    */
   
   public abstract Pattern getValidationPattern();
   
   
   /**
    * A short description about what this interaction does and how to interact syntactically correct with this command
    * 
    * @return the help text
    */
   public abstract String getHelp();
   
   public List<Object> perform(String call, NoPlanBlackBoardControl control, Interactor interactor){
	   
	   if(getValidationPattern().matcher(call).matches()){
		   return performInternal(call, control, interactor);
	   }else{
		   return Arrays.asList(new Object[]{new StringMessage("The parameters of the command: " + getKeyWord() + " could not get properly evaluated, please check the syntax. Help for this command is: \n" + getHelp())});
	   }
	   
	   
	   
   }
   
   /**
    * 
    * 
    * @param call
    * @param control
    * @param interactor
    * @return
    */
   public abstract List<Object>  performInternal(String call, NoPlanBlackBoardControl control, Interactor interactor);
   
   
   
}
